if (NOT WIN32)
  message(FATAL_ERROR "Windows only.")
endif ()

include(CheckSymbolExists)

if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
message(WARNING "Compiling Windows native binaries without 64-bit!")
endif()

# runtime library for linking: Mulit-threaded
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MT")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD")
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /MT")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")

check_symbol_exists("_M_AMD64" "" TARGET_X64)
if (TARGET_X64)
  set(BITS_SUFFIX "64")
else ()
  set(BITS_SUFFIX "")
endif ()

# aux_source_directory(. SRCS)

add_executable(${PROJECT_NAME}
  ByteBuffer.cpp
  ByteBuffer.h
  IconSwap.cpp
  IconSwap.h
  main.cpp
  VersionInfoSwap.cpp
  VersionInfoSwap.h
  cleaner.h
  cleaner.cpp
  javapackager.manifest
  javapackager.rc
)

set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} /d \"JFX_COMPANY=Oracle\"")
set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} /d \"JFX_COMPONENT=Java Packager Windows binary\"")
set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} /d \"JFX_NAME=Java Packager Windows 0.0.1\"")
set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} /d \"JFX_VER=0.0.1\"")
set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} /d \"JFX_BUILD_ID=0.0.1\"")
set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} /d \"JFX_COPYRIGHT=Copyright \\u00A9 2018\"")
set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} /d \"JFX_FVER=0.0.0.1\"")
set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} /d \"JFX_FTYPE=0x2L\"")
set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} /d JFX_FNAME=javapackager.exe")
set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} /d JFX_INTERNAL_NAME=javapackager")
set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} /l 0x409")

# 设置DEBUG宏
target_compile_definitions(${PROJECT_NAME} PUBLIC $<$<CONFIG:DEBUG>:DEBUG>)

# 设置输出目录
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)

# 设置输出文件名
set_target_properties(${PROJECT_NAME} PROPERTIES 
  OUTPUT_NAME "${PROJECT_NAME}${BITS_SUFFIX}"
  LINK_FLAGS "/SUBSYSTEM:CONSOLE" "/INCREMENTAL:NO" "/opt:REF"
)

target_compile_definitions(${PROJECT_NAME} PRIVATE UNICODE _UNICODE WIN32 _LITTLE_ENDIAN WIN32_LEAN_AND_MEAN _WIN32_WINDOWS=0X0500 _WIN32_WINNT=0X0500)
# If this is a CMake debug build, set _DEBUG compiler definition (used by native javapackager on Windows).
target_compile_definitions(${PROJECT_NAME} PUBLIC $<$<CONFIG:DEBUG>:_DEBUG>)
target_compile_options(${PROJECT_NAME} PRIVATE /nologo /W3 /EHsc /MT /GS /O2)
target_link_libraries(${PROJECT_NAME} kernel32 advapi32)